package com.yj.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;
import java.util.concurrent.TimeUnit;

/**
 * Feign配置
 *
 * @author hsj
 */
//@Configuration
/*public class FeignOkHttpClientConfig {

    private okhttp3.OkHttpClient okHttpClient;

    protected FeignOkHttpClientConfig() {
    }

    @Bean
    public ConnectionPool httpClientConnectionPool(FeignOkHttpClientProperties feignOkHttpClientProperties, OkHttpClientConnectionPoolFactory connectionPoolFactory) {
        Integer maxTotalConnections = feignOkHttpClientProperties.getMaxConnections();
        Long timeToLive = feignOkHttpClientProperties.getTimeToLive();
        return connectionPoolFactory.create(maxTotalConnections, timeToLive, TimeUnit.SECONDS);
    }

    @Bean
    public okhttp3.OkHttpClient client(FeignOkHttpClientProperties feignOkHttpClientProperties, ConnectionPool connectionPool) {
        this.okHttpClient = new okhttp3.OkHttpClient.Builder()
                .readTimeout(feignOkHttpClientProperties.getReadTimeout(), TimeUnit.MILLISECONDS)
                .connectTimeout(feignOkHttpClientProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
                .followRedirects(feignOkHttpClientProperties.isFollowRedirects())
                .connectionPool(connectionPool)
                .build();
        return this.okHttpClient;
    }

    @PreDestroy
    public void destroy() {
        if (this.okHttpClient != null) {
            this.okHttpClient.dispatcher().executorService().shutdown();
            this.okHttpClient.connectionPool().evictAll();
        }

    }

}*/
